package com.mir.dubbo.autoconfigure;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * dubbo配置
 *
 * @author Miracle.XJH
 * @title DubboProperties
 * @date 2017年02月19日 15:43:07
 */
@Configuration
@ConfigurationProperties(prefix = "dubbo")
@Slf4j
public class DubboProperties {
    private boolean enabled = true;
    private DubboApplication application;
    private DubboRegistry registry;
    private DubboProtocol protocol;
    private DubboProvider provider;
    private DubboConsumer consumer;

    public DubboApplication getApplication() {
        return application;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public void setApplication(DubboApplication application) {
        this.application = application;
    }

    public DubboRegistry getRegistry() {
        return registry;
    }

    public void setRegistry(DubboRegistry registry) {
        this.registry = registry;
    }

    public DubboProtocol getProtocol() {
        return protocol;
    }

    public void setProtocol(DubboProtocol protocol) {
        this.protocol = protocol;
    }

    public DubboProvider getProvider() {
        return provider;
    }

    public void setProvider(DubboProvider provider) {
        this.provider = provider;
    }

    public DubboConsumer getConsumer() {
        return consumer;
    }

    public void setConsumer(DubboConsumer consumer) {
        this.consumer = consumer;
    }

    /**
     * Dubbo Application Config
     *
     * @author Miracle.XJH
     * @title Application
     * @date 2017年02月19日 15:42:59
     */
    @Slf4j
    public static class DubboApplication {
        /**
         * The Name.
         * 应用名称
         */
        private String name = "demo-app";
        /**
         * The Logger.
         * 日志输出方式
         */
        private String logger;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getLogger() {
            return logger;
        }

        public void setLogger(String logger) {
            this.logger = logger;
        }
    }

    /**
     * Created by miracle on 2017/2/19.
     */
    @Slf4j
    public static class DubboProtocol {

        private String name;
        private int port = 20880;
        private String threadPool = "fixed";
        private String serialization = "java";
        private int threads = 500;

        public DubboProtocol() {

        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }

        public String getThreadPool() {
            return threadPool;
        }

        public void setThreadPool(String threadPool) {
            this.threadPool = threadPool;
        }

        public String getSerialization() {
            return serialization;
        }

        public void setSerialization(String serialization) {
            this.serialization = serialization;
        }

        public int getThreads() {
            return threads;
        }

        public void setThreads(int threads) {
            this.threads = threads;
        }
    }

    /**
     * Created by miracle on 2017/2/19.
     */
    @Slf4j
    public static class DubboRegistry {
        private String address = "zookeeper://localhost:2181";
        private String protocol = "zookeeper";

        public DubboRegistry() {

        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getProtocol() {
            return protocol;
        }

        public void setProtocol(String protocol) {
            this.protocol = protocol;
        }
    }

    public static class DubboProvider {
        private int connections = 5;
        private int timeout = 10000;
        private int retries = 0;
        private String version = "1.0";

        public int getConnections() {
            return connections;
        }

        public void setConnections(int connections) {
            this.connections = connections;
        }

        public int getTimeout() {
            return timeout;
        }

        public void setTimeout(int timeout) {
            this.timeout = timeout;
        }

        public int getRetries() {
            return retries;
        }

        public void setRetries(int retries) {
            this.retries = retries;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }
    }
    @Slf4j
    public static class DubboConsumer {
        private String version = "1.0";

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }
    }
}
